GTK+ Gnome Application Development by Havoc Pennington

GTK+ Gnome Application Development by Havoc Pennington

Author:Havoc Pennington
Language: eng
Format: mobi, pdf
Publisher: UNKNOWN
Published: 2018-06-18T23:00:00+00:00


Chaining Up

If an object overrides the shutdown, destroy, or finalize methods, it should chain up to the default implementation, to ensure that each parent class has a chance to clean up. Here is an example of chaining up:

static void

gtk_widget_real_destroy (GtkObject *object)

{

/* ... */ if (parent_class

>destroy)

parent_class>destroy (object);

};

gtk_widget_real_destroy() is installed in the widget’s class struct in the class initialization function, overwriting the GtkObject default. parent_class is a pointer to the parent’s class struct; usually you will want to store this pointer in your class initialization function, as GtkWidget does:

static GtkObjectClass *parent_class = NULL;

/* ... code omitted ... */

static void

gtk_widget_class_init (GtkWidgetClass *klass) {

GtkObjectClass *object_class;

object_class = (GtkObjectClass*) klass;

parent_class = gtk_type_class (gtk_object_get_type ()); /* ... code omitted ... */

object_class>set_arg = gtk_widget_set_arg; object_class>get_arg = gtk_widget_get_arg; object_class>shutdown = gtk_widget_shutdown; object_class>destroy = gtk_widget_real_destroy; object_class>finalize = gtk_widget_finalize;

}

Of course, if parent_class is not a GtkObjectClass*, you will need to cast it with the GTK_OBJECT_CLASS() macro.

An aside: notice that you should not chain up when implementing get_arg and set_arg — GTK+ special-cases these methods ingtk_object_set() andgtk_object_get(). Recall that the GtkObject base class initializer zeroes these two methods, rather than leaving the default implementation. When setting or getting an argument value, GTK+ uses the information provided on argument registration to jump directly to the correct class struct and invoke only the correct get_arg or set_arg method. Chaining up would be a much slower way to implement the same thing (and would require unique argument IDs within the same class ancestry).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.